package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {
    @Autowired
    private SettingManager settingManager;
    // 查询通用设置
    @GetMapping("/users/settings")
    public ResponseEntity findSettingVo(){
        //调用manage
        return  settingManager.findSettingVo();
    }

    //设置问题
    @PostMapping("/users/questions")
    public void setQuestion(@RequestBody Map<String,String>param){
        String content = param.get("content");
        settingManager.setQuestion(content);
    }

    //设置推送
       @PostMapping("/users/notifications/setting")
        public void setNotifications(@RequestBody Notification notification){
           settingManager.setNotifications(notification);
        }

        //黑名单查询
    @GetMapping("/users/blacklist")
    public ResponseEntity findBlackListByPage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum
                                               ,@RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){

           return    settingManager.findBlackListByPage(pageNum,pageSize);
    }

    //移除黑名单
    @DeleteMapping("/users/blacklist/{uid}")
    public void deleteByCondition(@PathVariable("uid")Long blackUserId){
             settingManager.deleteByCondition(blackUserId);
    }

    //发送短信
    @PostMapping("/users/phone/sendVerificationCode")
    public void sendSms(){
                 settingManager.sendSms();
    }

    //校验验证码
    @PostMapping("/users/phone/checkVerificationCode")
    public ResponseEntity checkNum(@RequestBody Map<String,String> param) {
        String verificationCode = param.get("verificationCode");
        return settingManager.checkNum(verificationCode);

    }
    //保存手机号
    @PostMapping("/users/phone")
    public void savePhone(@RequestBody Map<String,String> param){
        settingManager.savePhone(param.get("phone"));
    }
}
